﻿using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using DCS.AdministrationClient.DCS_Service;

namespace DCS.AdministrationClient.Forms
{
    public partial class ApplicationRunForm : Form
    {
        private readonly TaskInfo taskInfo;

        public ApplicationRunForm(TaskInfo taskInfo)
        {
            InitializeComponent();
            
            this.taskInfo = taskInfo;
            header.Text += string.Format(" \"{0}\"", taskInfo.Name);
        }

        private void TaskDirectoryClick(object sender, System.EventArgs e)
        {
            arguments.Text += string.Format(" \"{0}\"", Path.Combine(Directory.GetCurrentDirectory(), taskInfo.Id.ToString()));
        }

        private void PortionsNumberClick(object sender, System.EventArgs e)
        {
            arguments.Text += string.Format(" {0}", taskInfo.Name);
        }

        private void ClearPathClick(object sender, System.EventArgs e)
        {
            arguments.Clear();
        }

        private void BrowseClick(object sender, System.EventArgs e)
        {
            var result = openFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                path.Text = openFileDialog.FileName;
            }
        }

        private void RunClick(object sender, System.EventArgs e)
        {
            Process.Start(path.Text, arguments.Text);
        }
    }
}
